const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index () {
    const {ctx} = this
    ctx.body = 'api hi'
  }
  async article () {
    const {ctx, app} = this
    const results = await app.mysql.query(`
    SELECT 
      t1.id,
      t2.typeName,
      t1.title,
      t1.article_content  'articleContent',
      t1.introduce,
      t1.created_at 'createdAt',
      t1.view_count
      FROM article as t1
      JOIN type as t2
      ON t1.type_id = t2.id
    `)
    ctx.body = {count: results.length, data: results}
  }
}

module.exports = HomeController;
